<% layout('/layout/default.html', {title: '菜单管理', libs: ['dataGrid','validate']}){ %>
<div class="main-content">
		<div class="card-header">
				<i class="fa icon-book-open"></i> 菜单管理
			<div class="header-tools float-right">
			
				<a href="#" class="btn btn-default btn-sm " id="btnRefreshTree" title="刷新"><i class="fa fa-refresh"></i> 刷新</a>
				<a href="#" class="btn btn-default btn-sm " id="btnExpandTreeNode" title="展开全部"><i class="fa fa-angle-double-down"></i> 展开</a>
				<a href="#" class="btn btn-default btn-sm " id="btnCollapseTreeNode" title="折叠全部"><i class="fa fa-angle-double-up"></i> 折叠</a>
				<% if(hasPermi('sys:menu:edit')){ %>
					<a href="/sys/menu/form" class="btn btn-default btn-sm btnTool"  title="新增菜单"><i class="fa fa-plus"></i> 新增</a>
					
					<a href="#" class="btn btn-default btn-sm" id="btnUpdateSort" title="保存排序"><i class="fa fa-sort-amount-asc"></i> 保存排序</a>
				<% } %>
			</div>
		</div>
		<div class="container-fluid">
			<form id="searchForm" action="${ctx}/sys/menu/listData" method="post" class="form-inline d-none" >
				<div class="form-group">
					<button type="submit" class="btn btn-primary ">查询</button>
					<button type="reset" class="btn btn-sm btn-secondary ">重置</button>
				</div>
			</form>

			<form id="dataGridForm" action="${ctx}/sys/menu/updateSort" method="post" >
				<table id="dataGrid"></table>
			</form>
		</div>
</div>
<% } %>
<script>
	$('#dataGrid').dataGrid({
		searchForm: $("#searchForm"),
		columnModel: [
			{header:'菜单名称', name:'name', width:200, formatter: function(val, obj, row, act){
					return '<i class="'+row.icon+'"></i> <a href="/sys/menu/form?id='
							+row.id+'" class="btnList" data-title="编辑菜单">'+val+'</a>';
				}},
			{header:'链接', name:'href', width:150},
			{header:'排序', name:'sort', width:63, align:"center", formatter: function(val, obj, row, act){
					var html = [];
				<% if(hasPermi('sys:menu:edit')){ %>
						html.push('<input type="hidden" name="ids" value="'+row.id+'"/>');
						html.push('<input name="sorts" type="text" value="'+row.sort+'" style="width:50px;height:19px;margin:0;padding:0;text-align:center;border:1px solid #ddd">');
					<% }else{ %>
						html.push(row.sort);
					<% } %>
					return html.join('');
				}},
			{header:'可见', name:'isShow', width:50, fixed:true, align:"center", formatter: function(val, obj, row, act){
					return val=="1"?"显示":"隐藏";
				}},
			{header:'权限标识', name:'permission', width:150},
			{header:'操作', name:'actions', width:100, sortable:false, align:"center", formatter: function(val, obj, row, act){
					var actions = [];
				<% if(hasPermi('sys:menu:edit')){ %>
						actions.push('<a href="/sys/menu/form?id='+row.id+'" class="btnList" title="编辑菜单"><i class="fas fa-pencil-alt"></i></a>&nbsp;');
						actions.push('<a href="${ctx}/sys/menu/delete?id='+row.id+'" class="btnList" title="删除菜单" data-confirm="确认要删除该菜单及所有子菜单吗？" data-deltreenode="'+row.id+'"><i class="far fa-trash-alt"></i></a>&nbsp;');
						actions.push('<a href="/sys/menu/form?parentId='+row.id+'" class="btnList" title="新增下级菜单"><i class="fa fa-plus-square"></i></a>&nbsp;');
					<% } %>
					return actions.join('');
				}}
		],
		treeGrid: true,			// 启用树结构表格
		defaultExpandLevel: 0,
		expandNodeClearPostData: 'name',
		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});



	//绑定更新排序按钮
	$('#btnUpdateSort').click(function(){
		js.ajaxSubmitForm($("#dataGridForm"), function(data){
			if(data.result == "true"){
				$('#btnRefreshTree').click();
			}
			js.showMessage(data.message);
		});
	});
</script>